﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Lamex.mNC.Common
{
    public class GetParameter_Tools
    {
        /// <summary>
        /// 返回特定值
        /// </summary>
        /// <param name="dtParameter">刀具参数表</param>
        /// <param name="FEATURE_TYPE">部件类型</param>
        /// <param name="FEATURE_DIA">部件直径</param>
        /// <param name="SLOT_LENGTH">槽长</param>
        /// <param name="SLOT_WIDTH">槽宽</param>
        /// <param name="FILLIT_RADIUS">圆角半径</param>
        public static void Parameter_Tools(DataTable dtParameter, string FEATURE_TYPE, double FEATURE_DIA, double SLOT_LENGTH, double SLOT_WIDTH, double FILLIT_RADIUS,
           out string SUBROUTINE, out string TOOL_TYPE, out string TOOL_NO, out string COMPENSATION_NO, out double TOOL_DIA, out string EXPOSED_LENTH, out string ROTATE_SPEED,
               out string FEED_SPEED_H, out string FEED_SPEED_V, out string BLADE_LENTH)
        {
            SUBROUTINE = "";
            TOOL_TYPE = "";
            TOOL_NO = "";
            COMPENSATION_NO = "";
            TOOL_DIA = 0;
            EXPOSED_LENTH = "";
            ROTATE_SPEED = "";
            FEED_SPEED_H = "";
            FEED_SPEED_V = "";
            BLADE_LENTH = "";
            //按类型获取刀具参数返回值
            DataRow[] dr_HOLE = dtParameter.Select("TOOL_TYPE='钻头' and TOOL_DIA='" + FEATURE_DIA + "'");
            DataRow[] dr_TAPP = dtParameter.Select("TOOL_TYPE='丝锥' and TOOL_DIA='" + FEATURE_DIA + "'");
            DataRow[] dr_CK = dtParameter.Select("TOOL_TYPE='铣刀' and TOOL_DIA='6'");
            //HOLE
            if (FEATURE_TYPE == "HOLE" && dr_HOLE.Length > 0)
            {
                SUBROUTINE = "1_HOLE";
                TOOL_TYPE = dr_HOLE.CopyToDataTable().Rows[0]["TOOL_TYPE"].ToString();
                TOOL_NO = dr_HOLE.CopyToDataTable().Rows[0]["TOOL_NO"].ToString();
                COMPENSATION_NO = dr_HOLE.CopyToDataTable().Rows[0]["COMPENSATION_NO"].ToString();
                TOOL_DIA = Convert.ToDouble(dr_HOLE.CopyToDataTable().Rows[0]["TOOL_DIA"].ToString());
                EXPOSED_LENTH = dr_HOLE.CopyToDataTable().Rows[0]["EXPOSED_LENTH"].ToString();
                ROTATE_SPEED = dr_HOLE.CopyToDataTable().Rows[0]["ROTATE_SPEED"].ToString();
                FEED_SPEED_H = dr_HOLE.CopyToDataTable().Rows[0]["FEED_SPEED_H"].ToString();
                FEED_SPEED_V = dr_HOLE.CopyToDataTable().Rows[0]["FEED_SPEED_V"].ToString();
                BLADE_LENTH = dr_HOLE.CopyToDataTable().Rows[0]["BLADE_LENTH"].ToString();
            }
            //TAPP
            else if (FEATURE_TYPE == "TAPP" && dr_TAPP.Length > 0)
            {
                SUBROUTINE = "2_TAPP";
                TOOL_TYPE = dr_TAPP.CopyToDataTable().Rows[0]["TOOL_TYPE"].ToString();
                TOOL_NO = dr_TAPP.CopyToDataTable().Rows[0]["TOOL_NO"].ToString();
                COMPENSATION_NO = dr_TAPP.CopyToDataTable().Rows[0]["COMPENSATION_NO"].ToString();
                TOOL_DIA = Convert.ToDouble(dr_TAPP.CopyToDataTable().Rows[0]["TOOL_DIA"].ToString());
                EXPOSED_LENTH = dr_TAPP.CopyToDataTable().Rows[0]["EXPOSED_LENTH"].ToString();
                ROTATE_SPEED = dr_TAPP.CopyToDataTable().Rows[0]["ROTATE_SPEED"].ToString();
                FEED_SPEED_H = dr_TAPP.CopyToDataTable().Rows[0]["FEED_SPEED_H"].ToString();
                FEED_SPEED_V = dr_TAPP.CopyToDataTable().Rows[0]["FEED_SPEED_V"].ToString();
                BLADE_LENTH = dr_TAPP.CopyToDataTable().Rows[0]["BLADE_LENTH"].ToString();
            }
            // CPCK
            else if (FEATURE_TYPE == "HOLE" && FEATURE_DIA > 8 && dr_CK.Length > 0)
            {
                SUBROUTINE = "3_CPCK";
                TOOL_TYPE = dr_CK.CopyToDataTable().Rows[0]["TOOL_TYPE"].ToString();
                TOOL_NO = dr_CK.CopyToDataTable().Rows[0]["TOOL_NO"].ToString();
                COMPENSATION_NO = dr_CK.CopyToDataTable().Rows[0]["COMPENSATION_NO"].ToString();
                TOOL_DIA = Convert.ToDouble(dr_CK.CopyToDataTable().Rows[0]["TOOL_DIA"].ToString());
                EXPOSED_LENTH = dr_CK.CopyToDataTable().Rows[0]["EXPOSED_LENTH"].ToString();
                ROTATE_SPEED = dr_CK.CopyToDataTable().Rows[0]["ROTATE_SPEED"].ToString();
                FEED_SPEED_H = dr_CK.CopyToDataTable().Rows[0]["FEED_SPEED_H"].ToString();
                FEED_SPEED_V = dr_CK.CopyToDataTable().Rows[0]["FEED_SPEED_V"].ToString();
                BLADE_LENTH = dr_CK.CopyToDataTable().Rows[0]["BLADE_LENTH"].ToString();
            }
            //LPCK
            else if (FEATURE_TYPE == "LPCK" && SLOT_LENGTH >= 6 && SLOT_WIDTH >= 6 && dr_CK.Length > 0)
            {
                SUBROUTINE = "4_LPCK";
                TOOL_TYPE = dr_CK.CopyToDataTable().Rows[0]["TOOL_TYPE"].ToString();
                TOOL_NO = dr_CK.CopyToDataTable().Rows[0]["TOOL_NO"].ToString();
                COMPENSATION_NO = dr_CK.CopyToDataTable().Rows[0]["COMPENSATION_NO"].ToString();
                TOOL_DIA = Convert.ToDouble(dr_CK.CopyToDataTable().Rows[0]["TOOL_DIA"].ToString());
                EXPOSED_LENTH = dr_CK.CopyToDataTable().Rows[0]["EXPOSED_LENTH"].ToString();
                ROTATE_SPEED = dr_CK.CopyToDataTable().Rows[0]["ROTATE_SPEED"].ToString();
                FEED_SPEED_H = dr_CK.CopyToDataTable().Rows[0]["FEED_SPEED_H"].ToString();
                FEED_SPEED_V = dr_CK.CopyToDataTable().Rows[0]["FEED_SPEED_V"].ToString();
                BLADE_LENTH = dr_CK.CopyToDataTable().Rows[0]["BLADE_LENTH"].ToString();
            }
            //RPCK
            else if (FEATURE_TYPE == "RPCK" && SLOT_LENGTH >= 6 && SLOT_WIDTH >= 6 && FILLIT_RADIUS >= 3 && dr_CK.Length > 0)
            {
                SUBROUTINE = "5_RPCK";
                TOOL_TYPE = dr_CK.CopyToDataTable().Rows[0]["TOOL_TYPE"].ToString();
                TOOL_NO = dr_CK.CopyToDataTable().Rows[0]["TOOL_NO"].ToString();
                COMPENSATION_NO = dr_CK.CopyToDataTable().Rows[0]["COMPENSATION_NO"].ToString();
                TOOL_DIA = Convert.ToDouble(dr_CK.CopyToDataTable().Rows[0]["TOOL_DIA"].ToString());
                EXPOSED_LENTH = dr_CK.CopyToDataTable().Rows[0]["EXPOSED_LENTH"].ToString();
                ROTATE_SPEED = dr_CK.CopyToDataTable().Rows[0]["ROTATE_SPEED"].ToString();
                FEED_SPEED_H = dr_CK.CopyToDataTable().Rows[0]["FEED_SPEED_H"].ToString();
                FEED_SPEED_V = dr_CK.CopyToDataTable().Rows[0]["FEED_SPEED_V"].ToString();
                BLADE_LENTH = dr_CK.CopyToDataTable().Rows[0]["BLADE_LENTH"].ToString();
            }

        }
    }
}
